package activity.addCamera.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hichip.campro.R;
import com.hichip.tools.HiSearchSDK;

import java.util.ArrayList;
import java.util.List;

import bean.MyCamera;
import common.HiDataValue;

/**
 * Created by lt on 2017\12\16 0016.
 */

public class SearchResultListAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<HiSearchSDK.HiSearchResult> list = new ArrayList<HiSearchSDK.HiSearchResult>();
    private Context  mContext;

    public SearchResultListAdapter(Context context, List<HiSearchSDK.HiSearchResult> list) {
        this.mInflater = LayoutInflater.from(context);
        this.mContext=context;
        this.list=list;
    }

    public int getCount() {

        return list.size();
    }

    public Object getItem(int position) {

        return list.get(position);
    }

    public long getItemId(int position) {

        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        final HiSearchSDK.HiSearchResult result = (HiSearchSDK.HiSearchResult) getItem(position);
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_list_scam_result, null);
            holder = new ViewHolder();
            holder.uid = (TextView) convertView.findViewById(R.id.txt_camera_uid);
            holder.ip = (TextView) convertView.findViewById(R.id.txt_camera_ip);
            holder.state = (TextView) convertView.findViewById(R.id.txt_camera_state);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.uid.setText(result.uid);
        holder.ip.setText(result.ip);
        holder.uid.setTextColor(Color.rgb(0x00, 0x00, 0x00));
        holder.state.setText(" ");
        for (MyCamera camera : HiDataValue.CameraList) {
            if (camera.getUid().equalsIgnoreCase((result.uid))) {
                holder.uid.setTextColor(Color.rgb(0x99, 0x99, 0x99));
                holder.state.setText(mContext.getString(R.string.aleary_add_device));
            }
        }
        return convertView;
    }

    private final class ViewHolder {
        public TextView uid;
        public TextView ip;
        public TextView state;
    }
}
